<script setup>
import { chargemoney } from '/src/api/user.js'
import { useUserStore } from '@/stores'
// import { useRouter } from 'vue-router'
import { ref } from 'vue'
// const router = useRouter()
const userStore = useUserStore()
const formRef = ref()
const money = ref()
const charge = async () => {
  const res = await chargemoney(money.value)
  if (res.code == 1) {
    ElMessage.success(res.data)
  } else {
    ElMessage.error(res.data)
  }
  await userStore.getUser()
  // location.reload()
}
</script>
<template>
  <p style="text-align: center; margin-top: 10px">
    <strong>充值界面</strong>
  </p>
  <hr />
  <el-row style="margin-top: 200px">
    <el-col :span="18" :offset="4">
      <el-form :model="money" :rules="rules" ref="formRef" size="large" inline>
        <el-form-item>
          <span>目前余额:{{ userStore.user.balance }}</span>
        </el-form-item>
        <el-form-item label="充值金额" prop="money">
          <el-input v-model="money"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="charge" type="primary">提交</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>
<style lang="scss" scoped>
img {
  height: 150px;
  width: 150px;
}
button {
  height: 50px;
  width: 100px;
}
</style>
